<template>
	<view>
		<view v-if="loaded || list.itemIndex < 15" class="uni-indexed-list__title-wrapper">
			<text v-if="list.items && list.items.length > 0" class="uni-indexed-list__title">{{ list.key }}</text>
		</view>
		<view v-if="(loaded || list.itemIndex < 15) && list.items && list.items.length > 0"
			class="uni-indexed-list__list">
			<view v-for="(item, index) in list.items" :key="index" class="uni-indexed-list__item"
				hover-class="uni-indexed-list__item--hover">
				<view class="uni-indexed-list__item-container" @click="onClick(idx, index)">
					<view class="uni-indexed-list__item-border"
						:class="{'uni-indexed-list__item-border--last':index===list.items.length-1}">
						<view class="brand-tag">
							<image :src="item.imgSrc" class="tag" mode="aspectFit"></image>
							<text class="uni-indexed-list__item-content">{{ item.name }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'UniIndexedList',
		emits: ['itemClick'],
		props: {
			loaded: {
				type: Boolean,
				default: false
			},
			idx: {
				type: Number,
				default: 0
			},
			list: {
				type: Object,
				default () {
					return {}
				}
			},
			showSelect: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			onClick(idx, index) {
				this.$emit("itemClick", {
					idx,
					index
				})
			}
		}
	}
</script>

<style lang="scss">
	.uni-indexed-list__list {
		background-color: #e5e6eb;
		flex-wrap: wrap;
		justify-content: space-between;
		padding-left: 30rpx;
		padding-right: 50rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
	}

	.uni-indexed-list__item {
		font-size: 14px;
		/* #ifndef APP-NVUE */
		/* #endif */
		align-items: center;
		width: 40vw;
	}

	.uni-indexed-list__item-container {
		display: flex;
		align-items: center;
		background-color: #fff;
		border-radius: 40rpx;
		margin: 10rpx;
		/* #ifndef APP-NVUE */
		/* #endif */
		/* #ifdef H5 */
		cursor: pointer;
		/* #endif */
	}

	.uni-indexed-list__item-border {
		display: flex;
		flex: 1;
		/* #ifndef APP-NVUE */
		/* #endif */
		align-items: center;
		height: 80rpx;
	}

	.uni-indexed-list__item-border--last {
		border-bottom-width: 0px;
	}

	.brand-tag {
		display: flex;
		flex: 1;
		align-self: center;
		align-items: center;
		justify-content: space-around;
		padding: 10rpx;
		padding-right: 20rpx;

		.tag {
			height: 70rpx;
			width: 150rpx;
		}

		.uni-indexed-list__item-content {
			font-size: 30rpx;
			color: #000;
		}
	}

	.uni-indexed-list {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}


	// A B C...标题
	.uni-indexed-list__title-wrapper {
		/* #ifndef APP-NVUE */
		display: flex;
		width: 100%;
		/* #endif */
		background-color: #e5e6eb;
	}

	.uni-indexed-list__title {
		padding: 30rpx 40rpx;
		line-height: 24px;
		font-size: 30rpx;
		font-weight: 500;
	}
</style>
